using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Pong_Take1
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Bar : Microsoft.Xna.Framework.DrawableGameComponent
    {
        public Vector2 barPos;
        public Vector2 barTopRight, barBotLeft, barBotRight;

        public BoundingBox barBound;

        public Texture2D barTexture;

        public Bar(Game game, Vector2 barPos)
            : base(game)
        {
            // TODO: Construct any child components here
            this.barPos = barPos;            
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            barTopRight.X = barPos.X + barTexture.Width;
            barTopRight.Y = barPos.Y;
            barBotLeft.X = barPos.X;
            barBotLeft.Y = barPos.Y + barTexture.Height;
            barBotRight.X = barPos.X + barTexture.Width;
            barBotRight.Y = barPos.Y + barTexture.Height;

            barBound = new BoundingBox(new Vector3(barPos, 0), new Vector3(barBotRight.X, barBotRight.Y, 0));

            base.Update(gameTime);
        }      

        public void Draw(SpriteBatch sb)
        {            
            sb.Draw(this.barTexture, barPos, Color.White);            
        }

        public void Draw(SpriteBatch sb, float rotation)
        {
            Rectangle rec = new Rectangle((int)barPos.X, (int)barPos.Y, barTexture.Width, barTexture.Height);
            sb.Draw(this.barTexture, barPos, rec, Color.White, rotation, new Vector2(0,0), 1f, SpriteEffects.None, 0);
        }
    }
}
